<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        .weatcher{
            font-size: 32px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div id="test"></div>
    <div id="test1"></div>
    <div id="test2"></div>
    <script src="./js/react.development.js" crossorigin></script> 
    <script src="./js/react-dom.development.js" crossorigin></script>
    <script src="./js/babel.min.js"></script>
    <script src="./js/prop-types.js"></script>
    <script type="text/babel">
        // class Person extends React.Component{
        //     constructor(props) {
        //         super(props)
        //     }
        //     state = {name: '张三',age: 18,sex: '男'}
        //     static propTypes = {
        //         name: PropTypes.string.isRequired, // 限制name必传, 且 为字符串
        //         sex: PropTypes.string,// 限制sex为字符串
        //         age: PropTypes.number,// 限制age为数字
        //         speak: PropTypes.func// 限制speak为函数
        //     }
        //     static defaultProps = {
        //         sex: '不男不女',
        //         age: 18
        //     }
        //     render() {
        //         const {name,age,sex} = this.props
        //         return (
        //             <ul>
        //                 <li onClick={this.demo}>姓名: {name}</li>
        //                 <li>年龄: {age + 1}</li>
        //                 <li>性别: {sex}</li>
        //             </ul>
        //         )
        //     }

        //     demo = () => {
        //         console.log(this.props,'this.props')
        //     }


        // }

        function Person1 (props) {
            const {name,age, sex} = props
            const demo = () => {

            }
             return (
                    <ul>
                        <li onClick={demo}>姓名: {name}</li>
                        <li>年龄: {age + 1}</li>
                        <li>性别: {sex}</li>
                    </ul>
                )
        }

        Person1.propTypes = {
            name: PropTypes.string.isRequired, // 限制name必传, 且 为字符串
            sex: PropTypes.string,// 限制sex为字符串
            age: PropTypes.number,// 限制age为数字
            speak: PropTypes.func// 限制speak为函数
        }
        Person1.defaultProps = {
            sex: '女',
            age: 18
        }

        const p = {name: '老刘',age: 22}
        ReactDOM.render(<Person1 name="tom" age={18} />,document.getElementById('test'))
        ReactDOM.render(<Person1 name="Bob" age={19}/>,document.getElementById('test1'))
        ReactDOM.render(<Person1 {...p}/>,document.getElementById('test2'))
    </script>
</body>
</html>